#!/bin/bash

var='tmin'

rundir='/Volumes/TOSHIBA/climgroup_research_macbookair/HWA/manuscripts/C__HWAmicroclimate/companion_dataset/05_prism/'
depos=$rundir"/bil/"$var

cd $depos
rm $depos/wget.txt

prism="ftp://prism.nacse.org/daily/"$var

while read line

do

date=$line



echo $prism"/"${date:0:4}"/PRISM_"$var"_stable_4kmD2_"$date"_bil.zip" >> $depos/wget.txt


/usr/bin/wget -nc -i $depos/wget.txt -q -o /dev/null 


unzip $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.zip"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.bil.aux.xml"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.hdr"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.info.txt"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.prj"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.stn.csv"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.stx"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.xml"
rm $depos"/PRISM_"$var"_stable_4kmD2_"$date"_bil.zip"
rm $depos/wget.txt


done < $rundir/"dates.list"

exit
